﻿
using System;
using Test30.Core;

namespace Test30.Engine
{
    public class Hit
    {
        public Attack Attack{ get; }
        public INoun Attacker { get; }
        public bool CanDodge { get; }
        public Direction Direction { get; }

        public int Damage
        {
            get
            {
                if (!_damage.HasValue) throw new InvalidOperationException("Cannot access the Hit's Damage before it has been set by the defender.");

                return _damage.Value;
            }
        }

        public Hit(INoun attacker, Attack attack, bool canDodge, Direction direction)
        {
            Attacker = attacker;
            Attack = attack;
            CanDodge = canDodge;
            Direction = direction;
        }

        public Hit(INoun attacker, Attack attack, Direction direction)
            : this(attacker, attack, false, direction)
        {
        }

        public Effect CreateEffect(Vec position)
        {
            return new Effect(position, Direction, Attack.EffectType, Attack.Element);
        }

        public void SetDamage(int damage)
        {
            _damage = damage;
        }

        private int? _damage;

    }
}
